package top.glike.ssl.auto.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import top.glike.ssl.auto.domain.SslCertSyncLog;
import top.glike.ssl.auto.service.ISslCertSyncLogService;
import top.glike.ssl.common.annotation.Log;
import top.glike.ssl.common.core.controller.BaseController;
import top.glike.ssl.common.core.domain.AjaxResult;
import top.glike.ssl.common.core.page.TableDataInfo;
import top.glike.ssl.common.enums.BusinessType;
import top.glike.ssl.common.utils.poi.ExcelUtil;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 同步记录Controller
 *
 * @author Sophia
 * @date 2025-10-12
 */
@RestController
@RequestMapping("/auto/log")
public class SslCertSyncLogController extends BaseController {

    @Autowired
    private ISslCertSyncLogService sslCertSyncLogService;

    /**
     * 查询同步记录列表
     */
    @PreAuthorize("@ss.hasPermi('auto:log:list')")
    @GetMapping("/list")
    public TableDataInfo list(SslCertSyncLog sslCertSyncLog) {
        startPage();
        List<SslCertSyncLog> list = sslCertSyncLogService.selectSslCertSyncLogList(sslCertSyncLog);
        return getDataTable(list);
    }

    /**
     * 导出同步记录列表
     */
    @PreAuthorize("@ss.hasPermi('auto:log:export')")
    @Log(title = "同步记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SslCertSyncLog sslCertSyncLog) {
        List<SslCertSyncLog> list = sslCertSyncLogService.selectSslCertSyncLogList(sslCertSyncLog);
        ExcelUtil<SslCertSyncLog> util = new ExcelUtil<SslCertSyncLog>(SslCertSyncLog.class);
        util.exportExcel(response, list, "同步记录数据");
    }

    /**
     * 获取同步记录详细信息
     */
    @PreAuthorize("@ss.hasPermi('auto:log:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(sslCertSyncLogService.selectSslCertSyncLogById(id));
    }

    /**
     * 新增同步记录
     */
    @PreAuthorize("@ss.hasPermi('auto:log:add')")
    @Log(title = "同步记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SslCertSyncLog sslCertSyncLog) {
        return toAjax(sslCertSyncLogService.insertSslCertSyncLog(sslCertSyncLog));
    }

    /**
     * 修改同步记录
     */
    @PreAuthorize("@ss.hasPermi('auto:log:edit')")
    @Log(title = "同步记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SslCertSyncLog sslCertSyncLog) {
        return toAjax(sslCertSyncLogService.updateSslCertSyncLog(sslCertSyncLog));
    }

    /**
     * 删除同步记录
     */
    @PreAuthorize("@ss.hasPermi('auto:log:remove')")
    @Log(title = "同步记录", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(sslCertSyncLogService.deleteSslCertSyncLogByIds(ids));
    }
}
